<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\qbt_advertising\controller; //Demo插件英文名，改成你的插件英文就行了
use cmf\controller\PluginRestBaseController;
use think\Db;

class ApiIndexController extends PluginRestBaseController
{

    public function index()
    {
    	$param = $this->request->param();
    	$logo = $param['l'];
    	
        if(!empty($param['n'])){
            $num = $param['n'];
        }else{
            $num = '';
        }

    	$lists = Db::name('ad_position')->where(['ad_logo'=>$logo])->find();

    	$start=strtotime(date('Y-m-d H:i:s',time()));
    	$where['position_id'] = ['eq',$lists['id']];
    	$where['start_time'] = ['<= time', $start];
    	$where['end_time'] = ['>= time',$start];
    	$where['enabled'] = ['eq',1];
    	if($num){
    		$list = Db::name('ad')->where($where)->order('id desc')->limit($num)->select();
    	}else{
    		$list = Db::name('ad')->where($where)->order('id desc')->select();
    	}

        $this->success('success',['list'=>$list]);
    }

}